package com.gupaoedu.vip.netty.io.nio.channel;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @program:gupaoedu-vip-netty-io
 * @description:Filechannel demo
 * @author:Gongchao
 * @date:2020-04-27
 **/
public class FileInputDemo {

    public static void main(String[] args) throws Exception {
        FileInputStream fis = new FileInputStream("D://test.txt");

        FileChannel fc = fis.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

        fc.read(byteBuffer);

        byteBuffer.flip();

        while(byteBuffer.remaining() > 0) {
            byte b = byteBuffer.get();
            System.out.println((char)b);
        }

        fis.close();
        fc.close();
    }
}
